import {Injectable} from '@angular/core';
import {Response} from "@angular/http";
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from "@angular/router";
import {HttpService} from "@core/http/http.service";
import {Observable} from "rxjs";

import * as API from "@api/index";
import {GoodsRespVO, SNSResult} from "@interface/index";



@Injectable()
export class GoodsDetailsResolver implements Resolve<any> {

  constructor(private httpService: HttpService) {
  }

  /**
   * @description 商品详情接口
   * @author @chenwh576
   * @date 20170911
   * @type {string}
   */
  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<SNSResult<GoodsRespVO>> {
    const goodsCode = route.params['goodsCode'],
      url = `${API.GOODS_DETAIL}?goodsCode=${goodsCode}`;
    return this.httpService.get(url).map((res) => res.json());
  }

}
